package com.kproduce.roundcorners.util;

import ohos.agp.components.AttrHelper;
import ohos.app.Context;

/**
 * DensityUtil
 *
 * @author kuanggang on 2019/12/10
 * @since 2021-05-21
 */
public class DensityUtil {
    private static DensityUtil instance = null;

    private DensityUtil() {
    }

    /**
     * 静态锁对象
     *
     * @return Utils
     */
    public static synchronized DensityUtil getInstance() {
        if (instance == null) {
            instance = new DensityUtil();
        }
        return instance;
    }

    /**
     * 根据手机的分辨率将fp的单位转成px(像素)
     *
     * @param context 上下文
     * @param value fp
     * @return px
     */
    public static float dip2px(Context context, float value) {
        return AttrHelper.fp2px(value, context);
    }

    /**
     * 根据手机的分辨率将vp(像素)的单位转成px
     *
     * @param context 上下文
     * @param value vp
     * @return px
     */
    public static float px2dip(Context context, float value) {
        return AttrHelper.vp2px(value, context);
    }
}